<?php
class PagesController extends Controller{

/**
 * 单页列表
 * @return [type] [description]
 */
	public function actionList(){
		$criteria = new CDbCriteria();
		$criteria->order = 'id DESC';
		$pages = Pages::model()->findAll($criteria);
		$this->render('list', array('pages'=>$pages));
	}

	/**
	 * 添加单页
	 * @return [type] [description]
	 */
	public function actionAdd(){
		$model = new Pages();
		if(isset($_POST['Pages'])){
			//压入数据到model层
			$model->attributes = $_POST['Pages'];
			if($model->save()){
				$this->redirect(array('list'));
			}
		}
		Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/ueditor/ueditor.config.js');
		Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/ueditor/ueditor.all.min.js');
		Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/ueditor/lang/zh-cn/zh-cn.js');
		$this->render('add',array('model'=>$model));
	}

/**
 * 编辑单页
 * @return [type] [description]
 */
	public function actionEdit($id){
		$pages = Pages::model();
		if(isset($_POST['Pages'])){
			$pages->attributes = $_POST['Pages'];
			if($pages->save()){
				Yii::app()->user->setFlash('success', '修改成功');
				$this->redirect(array('list'));
			}
		}
		$page = $pages->findByPk($id);
		$page->content = CHtml::decode($page->content);
		Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/ueditor/ueditor.config.js');
		Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/ueditor/ueditor.all.min.js');
		Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/ueditor/lang/zh-cn/zh-cn.js');
		$this->render('edit',array('model'=>$page));
	}

/**
 * 删除单页
 * @return [type] [description]
 */
	public function actionDelete(){

	}
}